package com.fifth.user.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Comment;
import com.fifth.user.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    //查询该商品下的所有的评论信息
    @GetMapping("findComment/{goodsid}/{pageCurrent}/{pageSize}")
    public CommonResult findComment(@PathVariable String goodsid,@PathVariable Integer pageCurrent,@PathVariable Integer pageSize){
        return commentService.findComment(goodsid,pageCurrent,pageSize);
    }


    //查询该商品下的所有的评论信息
    @GetMapping("findMyComment/{goodsid}/{pageCurrent}/{pageSize}")
    public CommonResult findMyComment(@PathVariable String goodsid,@PathVariable Integer pageCurrent,@PathVariable Integer pageSize){
        return commentService.findMyComment(goodsid,pageCurrent,pageSize);
    }


    //查询该订单商品我的的评论
    @GetMapping("findByGoodsid")
    public CommonResult findByGoodsId(String code,String goodsid){
        return commentService.findByGoodsId(code,goodsid);
    }
    //根据id号删除评论
    @GetMapping("deleteById")
    public CommonResult deleteById(String id){
        return commentService.deleteById(id);
    }
    //根据修改评论及添加评论
    @PostMapping("updateComment")
    public CommonResult updateComment(@RequestBody Comment comment){
        return commentService.updateComment(comment);
    }
    //根据用户id查询出该用户所有订单信息
    @GetMapping("findByUserId")
    public CommonResult findByUserId(){
        return commentService.findByUserId();
    }

    //根据id查找评论
    @PostMapping("getCommentById/{id}")
    public CommonResult getCommentById(@PathVariable String id){
        return commentService.getCommentById(id);
    }

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @PostMapping("addComment")
    public CommonResult addComment(@RequestBody Comment comment){
        return commentService.addCommentByUid(comment);
    }


}
